package com.power.home.common.apkUpdate;

import com.google.gson.Gson;
import com.power.home.net.okHttp.RequestCenter;
import com.power.home.net.okHttp.listener.DisposeDataListener;

import org.json.JSONException;
import org.json.JSONObject;

public class UpdateInfoRequestCenter implements DisposeDataListener {

    private UpdateCallback handler;


    private  UpdateInfoRequestCenter(){

    }

    public void startGetUpdateInfo(){
        RequestCenter.requestUpdateInfo(this);
    }
    public  UpdateInfoRequestCenter(UpdateCallback callback){
     this.handler = callback;
    }

    @Override
    public void onSuccess(JSONObject responseObj) throws JSONException {
        boolean succeed = responseObj.getBoolean("succeed");
        if(succeed){
            JSONObject data = responseObj.getJSONObject("data");
           VersionResultBean bean = new Gson().fromJson(data.toString(),VersionResultBean.class);
           if(bean != null){
               if(handler != null){
                   handler.updateInfoFinshed(bean);
               }
           }

        }
    }

    @Override
    public void onSuccessConvetedToEntity(Object responesObj) {


    }

    @Override
    public void onFailure(Object reasonObj) {

    }

    public interface UpdateCallback{
        void updateInfoFinshed(VersionResultBean bean);


    }


}
